﻿using System;
using System.Collections.Generic;
using System.Text;
using System.BusinessObjects.Data;
using System.BusinessObjects.Validation;

namespace Blazing.BusinessObjects.Cms
{
    public class FeedbackItem : DataObject<FeedbackItem>
    {
        public virtual int ID
        {
            get { return GetValue<int>("ID"); }
            set
            {
                BeginEdit();
                SetValue("ID", value);
            }
        }

        [ValidationNotEmpty]
        public virtual string Name
        {
            get { return GetValue<string>("Name"); }
            set
            {
                BeginEdit();
                SetValue("Name", value);
            }
        }

        public virtual string Content
        {
            get { return GetValue<string>("Content"); }
            set
            {
                BeginEdit();
                SetValue("Content", value);
            }
        }

        public virtual bool IsApproved
        {
            get { return GetValue<bool>("IsApproved"); }
            set
            {
                BeginEdit();
                SetValue("IsApproved", value);
            }
        }

        [NonSerialized]
        StatisticSession _userSession;
        public virtual StatisticSession UserSession
        {
            get
            {
                return _userSession;
            }
            set
            {
                BeginEdit();
                _userSession = value;
            }
        }

        public virtual string UserName
        {
            get { return GetValue<string>("UserName"); }
            set
            {
                BeginEdit();
                SetValue("UserName", value);
            }
        }

        public virtual string UserEmail
        {
            get { return GetValue<string>("UserEmail"); }
            set
            {
                BeginEdit();
                SetValue("UserEmail", value);
            }
        }

        public virtual string UserUrl
        {
            get { return GetValue<string>("UserUrl"); }
            set
            {
                BeginEdit();
                SetValue("UserUrl", value);
            }
        }

        public virtual int UserRating
        {
            get { return GetValue<int>("UserRating"); }
            set
            {
                BeginEdit();
                SetValue("UserRating", value);
            }
        }

        public virtual DateTime CreatedDate
        {
            get { return GetValue<DateTime>("CreatedDate"); }
            set
            {
                SetValue("CreatedDate", value);
            }
        }

        public virtual DateTime RowStamp
        {
            get { return GetValue<DateTime>("RowStamp"); }
            set
            {
                SetValue("RowStamp", value);
            }
        }

        public FeedbackItem()
        {
            OnSaving += FeedbackItem_OnSaving;
        }

        void FeedbackItem_OnSaving(object sender, EventArgs e)
        {
            if (IsNull("CreatedDate"))
                CreatedDate = DateTime.Now;
        }
    }
}
